﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Imaginecup.iterator
{
    public class ListIterator:IIterator
    {
        private List<object> m_ObjectList;
        private int m_CurrentIndex = 0;

        public ListIterator()
        {
            m_ObjectList = new List<object>();
        }

        public void Add(object obj)
        {
            m_ObjectList.Add(obj);
        }

        public bool HasNext()
        {
            if (m_CurrentIndex  < m_ObjectList.Count)
                return true;
            return false;
        }

        public void Begin()
        {
            m_CurrentIndex = 0;
        }

        public object GetData()
        {
            object data = GetObject();
            m_CurrentIndex++;
            return data;
        }

      

        private object GetObject()
        {

            if (m_ObjectList.Count <= m_CurrentIndex)
                return null;

            return m_ObjectList[m_CurrentIndex];
        }
    }
}
